class StateSpace:
    """A state space consists of a set of named objects and possibly
    state constraints.  State constraints are lines of python code that
    are evaluated with the objects instantiated.

    A state is just a python dictionary, with keys drawn from 'names'."""
    def __init__(self,names,constraints=[]):
        self.names = names
        self.constraints = constraints

    def infeasible(self,s,env,cmax=0):
        """Given a State s and a temporary environment, evaluates whether
        any state constraints are violated.  Returns None if all constraints
        pass."""
        if len(self.constraints)==0: return None
        res = []
        for c in xrange(len(self.constraints)):
            if not eval(self.constraints[c],env,s):
                res.append(c)
                if cmax > 0 and len(res) >= cmax:
                    return res
        if len(res)==0:
            return None
        return res
        
